home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / E / PsiloPlayer / Src / Modules / replay / replayer.s < prev    next >
Encoding:
Text File  |  1996-03-21  |  3.9 KB  |  227 lines

  1. *
  2. * Generic code for music replayers,
  3. *  a little based on the P61 replayer code
  4. *
  5. *   by Petter E. Stokke, Stardate 6600.2
  6. *
  7.  
  8.     include    exec/funcdef.i
  9.     include    exec/exec_lib.i
  10.     include    exec/interrupts.i
  11.     include    exec/memory.i
  12.  
  13. LVO    macro
  14.     jsr    _LVO\1(a6)
  15.     endm
  16. LVOEXE    macro
  17.     move.l    4.w,a6
  18.     LVO    \1
  19.     endm
  20.  
  21.  
  22.     XDEF    dti_AudioAlloc,dti_AudioFree,dti_StartInt__i,dti_StopInt,dti_SetSpeed__i
  23.  
  24. *
  25. * dti_AudioAlloc - allocates audio channels, returns TRUE upon success.
  26. *
  27.  
  28. dti_AudioAlloc    movem.l    d1-a6,-(sp)
  29.         moveq    #-1,d0
  30.         LVOEXE    AllocSignal
  31.         move.b    d0,sigBit
  32.         bmi.s    dti_AudioFree
  33.         lea    audioPort,a1
  34.         move.l    a1,aPort
  35.         move.b    d0,15(a1)
  36.         move.l    a1,-(sp)
  37.         sub.l    a1,a1
  38.         jsr    -$126(a6)
  39.         move.l    (sp)+,a1
  40.         move.l    d0,16(a1)
  41.         lea    reqList,a0
  42.         move.l    a0,(a0)
  43.         addq.l    #4,(a0)
  44.         clr.l    4(a0)
  45.         move.l    a0,8(a0)
  46.         lea    audioData,a1
  47.         move.l    a1,reqData
  48.         lea    allocReq,a1
  49.         lea    audioname,a0
  50.         moveq    #0,d0
  51.         moveq    #0,d1
  52.         LVO    OpenDevice
  53.         tst.b    d0
  54.         bne.s    dti_AudioFree
  55.         st    audioOpen
  56.         moveq    #-1,d0
  57.         movem.l    (sp)+,d1-a6
  58.         rts
  59.  
  60. *
  61. * dti_AudioFree - frees audio channels if allocated. Safe to call anytime.
  62. *
  63.  
  64. dti_AudioFree    movem.l    d1-a6,-(sp)
  65.         move.l    4.w,a6
  66.         tst.b    audioOpen
  67.         beq.s    .1
  68.         lea    allocReq,a1
  69.         jsr    -$1c2(a6)
  70.         clr.b    audioOpen
  71. .1        moveq    #0,d0
  72.         move.b    sigBit,d0
  73.         bmi.s    .end
  74.         LVO    FreeSignal
  75.         st    sigBit
  76. .end        moveq    #0,d0
  77.         movem.l    (sp)+,d1-a6
  78.         rts
  79.  
  80. *
  81. * dti_StartInt - launches a CIA timer interrupt with the code pointed to
  82. *                by the parameter on the stack. Returns TRUE upon success.
  83. *
  84.  
  85. dti_StartInt__i    move.l    4(sp),d0
  86.         move.l    d0,intcode
  87.         movem.l    d1-a6,-(sp)
  88.         move.l    4.w,a6
  89.         cmp.b    #60,$213(a6)
  90.         beq.s    .ntsc
  91.         move.l    #1773447,d0
  92.         bra.s    .setcia
  93. .ntsc        move.l    #1789773,d0
  94. .setcia        move.l    d0,timer
  95.         divu    #125,d0
  96.         move.w    d0,thi
  97. .timerset    clr.w    server
  98.         lea    timerint,a1
  99.         move.l    a1,timerdata
  100.         lea    intServer,a1
  101.         move.l    a1,timerdata+8
  102.         moveq    #0,d3
  103.         lea    cianame,a1
  104. .openciares    moveq    #0,d0
  105.         LVO    OpenResource
  106.         move.l    d0,ciares
  107.         beq.s    .err
  108.         move.l    d0,a6
  109.         lea    timerinterrupt,a1
  110.         moveq    #0,d0
  111.         jsr    -6(a6)
  112.         tst.l    d0
  113.         beq.s    .gottimer
  114.         addq.l    #4,d3
  115.         lea    timerinterrupt,a1
  116.         moveq    #1,d0
  117.         jsr    -6(a6)
  118.         tst.l    d0
  119.         bne.s    .err
  120. .gottimer    lea    craddr+8,a6
  121.         lea    ciaaddr,a0
  122.         move.l    (a0,d3),d0
  123.         move.l    d0,(a6)
  124.         sub.w    #$100,d0
  125.         move.l    d0,-(a6)
  126.         moveq    #2,d3
  127.         btst    #9,d0
  128.         bne.s    .timerb
  129.         subq.b    #1,d3
  130.         add.w    #$100,d0
  131. .timerb        add.w    #$900,d0
  132.         move.l    d0,-(a6)
  133.         move.l    d0,a0
  134.         and.b    #%10000000,(a0)
  135.         move.b    d3,timerOpen
  136.         moveq    #-1,d0
  137.         move.l    craddr+4,a1
  138.         move.b    tlo,(a1)
  139.         move.b    thi,$100(a1)
  140.         or.b    #$19,(a0)
  141.         bra.s    .end
  142. .err        moveq    #0,d0
  143. .end        movem.l    (sp)+,d1-a6
  144.         rts
  145.  
  146. *
  147. * dti_StopInt - stops the timer interrupt if it's running.
  148. *
  149.  
  150. dti_StopInt    movem.l    d0-a6,-(sp)
  151.         moveq    #0,d0
  152.         move.b    timerOpen,d0
  153.         beq.s    .end
  154.         move.l    ciares,a6
  155.         lea    timerinterrupt,a1
  156.         subq.b    #1,d0
  157.         jsr    -12(a6)
  158.         clr.b    timerOpen
  159. .end        movem.l    (sp)+,d0-a6
  160.         rts
  161.  
  162. intServer    movem.l    d2-d7/a2-a6,-(sp)
  163.         lea    softInt,a1
  164.         LVOEXE    Cause
  165.         move.l    craddr+4,a0
  166.         move.b    tlo,(a0)
  167.         move.b    thi,$100(a0)
  168.         movem.l    (sp)+,d2-d7/a2-a6
  169.         moveq    #1,d0
  170.         rts
  171.  
  172. *
  173. * dti_SetSpeed - sets the timer speed to the number of BPM
  174. *                passed on the stack.
  175. *
  176.  
  177. dti_SetSpeed__i    move.l    4(sp),d0
  178.         movem.l    d1/a1,-(sp)
  179.         move.l    timer(pc),d1
  180.         divu    d0,d1
  181.         move.w    d1,thi
  182.         movem.l    (sp)+,d1/a1
  183.         rts
  184.  
  185.  
  186.  
  187. intName        dc.b    "ProTracker Interrupt Server",0
  188. audioname    dc.b    "audio.device",0
  189. cianame        dc.b    "ciab.resource",0
  190.     even
  191. thi        ds.b    1
  192. tlo        ds.b    1
  193. audioData    dc.w    $0f00
  194. audioPort    dc.l    0,0
  195.         dc.b    4,0
  196.         dc.l    0
  197.         dc.b    0,0
  198.         dc.l    0
  199. reqList        dc.l    0,0,0
  200.         dc.b    5,0
  201. allocReq    dc.l    0,0
  202.         dc.w    127
  203.         dc.l    0
  204. aPort        dc.l    0
  205.         dc.w    68
  206.         dc.l    0,0,0
  207.         dc.w    0
  208. reqData        dc.l    0,1,0,0,0,0,0,0
  209.         dc.w    0
  210. server        dc.w    0
  211. miscbase    dc.l    0
  212. ciares        dc.l    0
  213. craddr        dc.l    0,0,0
  214. timerinterrupt    dc.w    0,0,0,0,127
  215. timerdata    dc.l    0,0,0
  216. timer        dc.l    0
  217. softInt        dc.l    0,0
  218.         dc.b    NT_INTERRUPT,32
  219.         dc.l    intName,0
  220. intcode        dc.l    0
  221. ciaaddr        dc.l    $bfd500,$bfd700
  222. timerint    dc.b    'x',0
  223. sigBit        dc.b    -1
  224. audioOpen    dc.b    0
  225. timerOpen    dc.b    0
  226.  
  227.